using Electric.EntityFrameworkCore.DependencyInjection;
using Microsoft.EntityFrameworkCore;
using System.Reflection;

var builder = WebApplication.CreateBuilder(args);

//EntityFrameworkCore注入
var provider = builder.Configuration.GetValue<string>("DataProvider");
var connection = string.Empty;

//数据库类型
var dbType = DbType.Sqlite;
//启用的数据库类型
switch (provider)
{
    case "MsSql":
        connection = builder.Configuration.GetConnectionString("MsSqlConnection") ?? throw new InvalidOperationException("MsSqlConnection在appsettings.json未发现");
        dbType = DbType.SqlServer;
        break;
    case "MySql":
        connection = builder.Configuration.GetConnectionString("MySqlConnection") ?? throw new InvalidOperationException("MySqlConnection在appsettings.json未发现");
        dbType = DbType.MySql;
        break;
    case "Sqlite":
        connection = builder.Configuration.GetConnectionString("SqliteConnection") ?? throw new InvalidOperationException("SqliteConnection在appsettings.json未发现");
        dbType = DbType.Sqlite;
        break;
}


builder.Services.AddEntityFrameworkCore(dbType, connection, Assembly.GetExecutingAssembly().FullName);


var app = builder.Build();
app.Run();